package cn.zhaoyuening.demo.zkdemo.zkdemo.conf;

import cn.zhaoyuening.fanrpc.provider.core.RpcServer;
import org.apache.curator.RetryPolicy;
import org.apache.curator.framework.CuratorFramework;
import org.apache.curator.framework.CuratorFrameworkFactory;
import org.apache.curator.retry.ExponentialBackoffRetry;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

@Configuration
public class BeanConf {
    @Value("${funrpc.zookeeper.address}")
    private String ZK_ADDRESS;

    @Bean
    public RpcServer rpcServer() {
        RpcServer rpcServer = new RpcServer();
        return rpcServer;
    }

    @Bean
    public CuratorFramework zkClient() {
        RetryPolicy retryPolicy = new ExponentialBackoffRetry(1000, 3);
        CuratorFramework client = CuratorFrameworkFactory.newClient(ZK_ADDRESS, retryPolicy);
        client.start();
        return client;
    }
}
